﻿@using NFine.Domain._03_Entity.Biz
@{
    ViewBag.Title = "提现管理";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script src="~/Content/js/datepicker/WdatePicker.js"></script>
<script src="~/Content/js/jqgrid/jqgrid.min.js"></script>
<link href="~/Content/js/jqgrid/jqgrid.css" rel="stylesheet" />
<script src="~/Content/js/jqgrid/grid.locale-cn.js"></script>
<style type="text/css">
    .table {
        width: 100%;
        margin-bottom: 20px;
    }

        .table thead tr {
            background: #F2F8FC;
        }

        .table tbody tr {
            background-color: white;
        }

        .table tr td, .table tr th {
            padding: 8px;
            border: 1px solid #ccc;
            border-top: 1px solid #ccc;
            text-align: center;
            line-height: 23px;
        }
</style>
<script>
    var userMoney;
    var type = -2;
    $(function() {
        //////initControl();
        ////////获取供货商余额信息
        //////getProperty();


        //获取供货商提现记录
        gridList(-2);
        $('#ulOrder a').click(function(e) {
            type = $(this).attr("type");
            $("#btn_search").click();
        });

    });

    function initControl() {
        $("#txt_BankType").on('change', function() {
            $('#txt_bank').val("");
            $('#txt_people').val("");
            $('#txt_bankCaid').val("");
            if ($(this).val() != '-1') {
                var $option = $(this).find('option:selected');
                $('#txt_bank').val($option.attr('data-bank'));
                $('#txt_people').val($option.attr('data-man'));
                $('#txt_bankCaid').val($option.attr('data-card'));
            }
        });
    }

    // 增加用户银行卡信息
    function addBankCard() {
        $.modalOpen({
            id: "Form",
            title: "添加银行卡",
            url: "/MemberManage/MemberWithdrawals/Form",
            width: "550px",
            height: "400px",
            callBack: function(iframeId) {
                top.frames[iframeId].submitForm();
                //$.currentWindow().$(".toolbar .operate").find('.close').click();
            }
        });
    }

    // 打开提现窗口
    function withdraw() {
        $.modalOpen({
            id: "Form",
            title: "提现",
            url: "/MemberManage/MemberWithdrawals/WithDraw",
            width: "450px",
            height: "400px",
            callBack: function(iframeId) {
                top.frames[iframeId].submitForm();
                //$.currentWindow().$(".toolbar .operate").find('.close').click();
            }
        });
    }

    //获取提现记录
    function gridList(t) {
        type = t;
        var $gridList = $("#gridList");

        var postData = {
            Type: type,
            WithdrawalsTimeStart: $("#txt_startDate").val(),
            WithdrawalsTimeEnd: $("#txt_endDate").val()
        };
        $gridList.dataGrid({
            url: "/MemberManage/MemberWithdrawals/GetListForWithdrawals",
            postData: postData,
            height: $(window).height() - 158,
            colModel: [
                { label: '提现流水号', name: 'F_SerialNumber', width: 150, align: 'center', sortable: false },
                { label: '申请人账号', name: 'UserName', width: 150, align: 'center', sortable: false },
                { label: '申请人姓名', name: 'RealName', width: 150, align: 'center', sortable: false },
                { label: '申请人联系方式', name: 'CellPhone', width: 150, align: 'center', sortable: false },
                {
                    label: '申请提现金额(元)',
                    name: 'F_WithdrawalsMoney',
                    width: 100,
                    align: 'center',
                    sortable: false,
                    formatter: function(cellvalue, options, rowObject) {
                        return cellvalue == null ? "" : parseFloat(cellvalue).toFixed(2);
                    }
                },
                { label: '申请人开户行', name: 'OpeningBank', width: 150, align: 'center', sortable: false },
                { label: '开户人', name: 'AccountName', width: 150, align: 'center', sortable: false },
                { label: '银行卡号', name: 'Account', width: 150, align: 'center', sortable: false },
                { label: '申请时间', name: 'F_WithdrawalsTime', width: 150, align: 'center', sortable: false },
                {
                    label: '处理状态',
                    name: 'F_WithdrawalsStatus',
                    width: 100,
                    align: 'center',
                    sortable: false,
                    formatter: function(cellvalue) {
                        switch (cellvalue) {
                        case 0:
                            return "未打款";
                            break;
                        case 1:
                            return "已打款";
                            break;
                        }
                    }
                }
            ],
            pager: "#gridPager",
            sortname: 'F_WithdrawalsTime desc',
            viewrecords: true
        });

        $("#btn_search").click(function() {
            var postData = {
                Type: type,
                WithdrawalsTimeStart: $("#txt_startDate").val(),
                WithdrawalsTimeEnd: $("#txt_endDate").val()
            };
            $gridList.jqGrid('setGridParam', {
                postData: postData
            }).trigger('reloadGrid');
        });
    }

    //获取供货商资产信息
    function getProperty() {
        $.ajax({
            url: "/MemberManage/MemberWithdrawals/GetProperty",
            success: function(result) {
                var data = eval('(' + result + ')');
                $('#userProperty').html(data.userProperty);
                userMoney = data.userProperty;
            }
        });
    }

    //提现
    function btn_tx() {
        var userProperty = $('#userProperty').html();
        var money = $('#txt_money').val();
        var bankId = $('#txt_BankType').val();
        if (bankId == '-1') {
            alert("请选择银行卡！");
            return;
        }

        if (parseFloat(money).toFixed(2) > parseFloat(userProperty).toFixed(2)) {
            alert("请重新输入提现金额！");
            return;
        }
        $.submitForm({
            url: "/MemberManage/MemberWithdrawals/Withdrawals",
            param: { money: money, bankId: bankId },
            success: function() {
                $.reload();
            }
        });
    }

</script>


            

    <div class="topPanel">
        <div class="search">
            <table>
                <tr>
                    <td>
                        <div class="input-group">
                            <input id="txt_startDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="申请日期" style="width: 150px;" />
                            --
                            <span style="float: right; margin-left: 3px;"> <input id="txt_endDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="申请日期" style="width: 150px;" /></span>
                            <span class="input-group-btn">
                                <button id="btn_search" type="button" class="btn  btn-primary" title="搜索"><i class="fa fa-search"></i></button>
                            </span>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="toolbar">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>

            <div class="btn-group">
                <a class="btn btn-primary" onclick="addBankCard()"><span class="glyphicon glyphicon-plus">增加银行卡</span></a>
            </div>

            <div class="btn-group">
                @*<button id="btn_tx" type="button" class="btn  btn-primary" style="width: 90px;" onclick='javascript: withdraw()'>提现</button>*@
                <a class="btn btn-primary" onclick="withdraw()"><span class="glyphicon">提现</span></a>
            </div>
        </div>
    </div>
        


    <div class="tab-content content">
        <ul class="nav nav-tabs" role="tablist" id="ulOrder">
            <li role="presentation" class="active"><a href="#home" type="-2" id="ahome" aria-controls="home" role="tab" data-toggle="tab">全部提现记录</a></li>
            <li role="presentation"><a href="#home" type="0" aria-controls="profile" role="tab" data-toggle="tab">待审核</a></li>
            <li role="presentation"><a href="#home" type="1" aria-controls="profile" role="tab" data-toggle="tab">已打款</a></li>
        </ul>
        <div role="tabpanel" class="tab-pane active " id="home">
            <div class="gridPanel" id="baseInfo" class="tab-pane fade in active">
                <table id="gridList"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>



    <script type="text/javascript">
    $(document).ready(function () {

    });
    </script>
